app.service('vipService',['$http','$q','utilService',function($http,$q,utilService){

    this.findById = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'vip/find',
            params:{id:$scope.vipId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.addVip = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'vip',
            data:$scope.vip,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.delete = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'vip',
            data:$scope.id,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateVip = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'vip/update',
            data:$scope.vipVO,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);